﻿/**
 * Scroller
 * ---------------------
 * VERSION: 1.0
 * DATE: 4/08/2010
 * AS3
 * UPDATES AND DOCUMENTATION AT: http://www.FreeActionScript.com
 **/
package org.nickro.project
{
	import flash.display.MorphShape;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@------对应的mc可能需个改:   thumb_mc 拉条块  track_mc 拉条线  
	
	public class ScrollBar_link extends MovieClip
	{
		private var yOffset:Number;
		private var yMin:Number;
		private var yMax:Number;
		
		private var thumb_mc_this:MovieClip;
		private var track_mc_this:MovieClip;
		
		public function ScrollBar_link()
		{
			thumb_mc_this = thumb_mc;//转换
			track_mc_this = track_mc;
			
			yMin = 0;
			yMax = track_mc_this.height - thumb_mc_this.height;
			thumb_mc_this.addEventListener(MouseEvent.MOUSE_DOWN, thumbDown);
			stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp);
		}
		
		private function thumbDown(event:MouseEvent):void
		{
			stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
			yOffset = mouseY - thumb_mc_this.y;
		}

		private function thumbUp(event:MouseEvent):void
		{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
		}

		private function thumbMove(event:MouseEvent):void
		{
			thumb_mc_this.y = mouseY - yOffset;
			
			if (thumb_mc_this.y <= yMin)
			{				
				thumb_mc_this.y = yMin;
			}
			if (thumb_mc_this.y >= yMax)
			{
				thumb_mc_this.y = yMax;
			}
			
			dispatchEvent(new ScrollBarEvent_link(thumb_mc_this.y / yMax));
			
			event.updateAfterEvent();
		}
	}
}
